import 'package:favoritecate/core/viewmodel/filter_viewmodel.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class FYFilterContent extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        buildTitle(context),
        buildList(context)
      ],
    );
  }

  Widget buildTitle(BuildContext context){
    return Container(
      padding: EdgeInsets.symmetric(vertical: 20),
      alignment:Alignment.center,
      child: Text('展示你的选择',style: Theme.of(context).textTheme.display3.copyWith(fontWeight: FontWeight.bold),),
    );
  }

  Widget buildList(BuildContext context){
//    shrinkWrap: true,

//    //无谷蛋白
//    bool _isGlutenfree = false;
//    //有无乳糖
//    bool _isLactorsefree = false;
//    //素食主义
//    bool _isVegetarian = false;
//    //严格素食主义
//    bool _isVegan = false;
    return Consumer<FYFilterViewModel>(
      builder: (ctx,filter,child){
        return Expanded(
          child: ListView(
            children: <Widget>[
              buildListTitle('无谷蛋白', '展示无谷蛋白食物', filter.isGlutenfree,(value){
                filter.isGlutenfree = value;
              }),
              buildListTitle('不含乳糖', '展示不含乳糖食物',filter.isLactorsefree, (value){
                filter.isLactorsefree = value;
              }),
              buildListTitle('普通素食者', '展示普通素食相关食物',filter.isVegetarian,(value){
                filter.isVegetarian = value;
              }),
              buildListTitle('严格素食者' , '展示严格素食相关食物',filter.isVegan, (value){
                filter.isVegan = value;
              })
            ],
          ),
        );
      },
    );
  }
//
  Widget buildListTitle(String title,String subtitle,bool value,Function onChange){
    return ListTile(
      title: Text(title),
      subtitle: Text(subtitle),
      trailing:  Switch(
        value: value,
        onChanged: onChange,
      ),
    );
  }

}
